﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Film.Common;


namespace Film.Repository
{
   public class tblOccupationRepository : Repository<tblOccupation>
    {
        public tblOccupation GetByOccID(int occID)
        {
            return dataContext.tblOccupations.FirstOrDefault(x => x.OccupationID == occID);
        }

        public List<tblOccupation> Filter(string keyWord, int start, int limit, out int count)
        {
            keyWord = UtilString.XacDinhNguyenAm(keyWord);
            var result = (from ds in dataContext.tblOccupations
                          where (keyWord == "" ||
                          (keyWord != "" && (System.Data.Linq.SqlClient.SqlMethods.Like(ds.OccupationName, "%" + keyWord + "%"))))
                          select ds);

            count = result.Count();
            return result.Skip(start).Take(limit).ToList();
        }
        public int GetNextID()
        {
            tblOccupation entity = dataContext.tblOccupations.OrderByDescending(x => x.OccupationID).FirstOrDefault();
            if (entity != null)
            {
                return entity.OccupationID + 1;
            }
            return 1;
        }

    }
}
